package com.mzw.huaxiarealestatebackend.controller;

import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.Result;
import com.mzw.huaxiarealestatebackend.entity.StaffWorkRecord;
import com.mzw.huaxiarealestatebackend.service.StaffWorkRecordService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (StaffWorkRecord)表控制层
 *
 * @author makejava
 * @since 2023-12-22 00:03:04
 */
@RestController
@RequestMapping("staffWorkRecord")
public class StaffWorkRecordController {
    /**
     * 服务对象
     */
    @Resource
    private StaffWorkRecordService staffWorkRecordService;

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping
    public Result<BackPage<StaffWorkRecord>> queryAll(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize){
        BackPage<StaffWorkRecord> page = staffWorkRecordService.queryByPage(currentPage, pageSize);
        return Result.success(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result<StaffWorkRecord> queryById(@PathVariable("id") String id) {
        StaffWorkRecord staffWorkRecord = this.staffWorkRecordService.queryById(id);
        if (staffWorkRecord != null){
            return Result.success(staffWorkRecord);
        }
        return Result.error("查找失败");
    }

    /**
     * 新增数据
     *
     * @param staffWorkRecord 实体
     * @return 新增结果
     */
    @PostMapping
    public Result<StaffWorkRecord> add(@RequestBody StaffWorkRecord staffWorkRecord) {
        boolean insert = this.staffWorkRecordService.insert(staffWorkRecord);
        if (insert){
            return Result.success();
        }
        return Result.error("添加失败");
    }

    /**
     * 编辑数据
     *
     * @param staffWorkRecord 实体
     * @return 编辑结果
     */
    @PutMapping
    public Result<StaffWorkRecord> edit(@RequestBody StaffWorkRecord staffWorkRecord) {
        boolean update = this.staffWorkRecordService.update(staffWorkRecord);
        if (update){
            return Result.success();
        }
        return Result.error("修改失败");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public Result<StaffWorkRecord> deleteById(@RequestParam("id") String id) {
        boolean b = this.staffWorkRecordService.deleteById(id);
        if (b){
            return Result.success();
        }
        return Result.error("删除失败");
    }

}

